﻿/*
 DotNetNuke - http://www.dotnetnuke.com
 Copyright (c) 2002-2010 by DotNetNuke Corp.

 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
 documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
 the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
 to permit persons to whom the Software is furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all copies or substantial portions 
 of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 DEALINGS IN THE SOFTWARE.

*/
using System;
using System.Collections;

using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.UI.Modules;


namespace DotNetNuke.Modules.UserDefinedTable
{




  public abstract class BaseController
  {


    protected ModuleInfo _configuration;
    //private int _moduleId;
    protected Hashtable _moduleSettings;
    //private int _portalId;
    private DotNetNuke.Entities.Portals.PortalInfo _portalInfo;
    //private int _tabId = Null.NullInteger;
    //private int _tabModuleId = Null.NullInteger;
    //private UserInfo _userinfo;



    protected BaseController()
    {}




    public void initialise(ModuleInfo ModuleInfo)
    {
      this.Configuration = ModuleInfo;
    }




    public void initialise(ModuleInstanceContext context)
    {
      this.Settings = context.Settings;
      this.Configuration = context.Configuration;
      this.User = context.PortalSettings.UserInfo;
    }





    public void initialise(int ModuleId)
    {
      this.ModuleID = ModuleId;
    }




    public void initialise(int ModuleId, int TabId, UserInfo User)
    {
      this.ModuleID = ModuleId;
      this.TabId = TabId;
      this.User = User;
    }




    public ModuleInfo Configuration
    {
      get
      {
        return this._configuration;
      }
      set
      {
        this._configuration = value;
        this.ModuleID = value.ModuleID;
        this.TabModuleId = value.TabModuleID;
        this.TabId = value.TabID;
        this.PortalId = value.PortalID;
      }
    }




    public int ModuleID
    { get; set; }




    protected int PortalId
    { get; set; }




    public DotNetNuke.Entities.Portals.PortalInfo PortalInfo
    {
      get
      {
        if (this._portalInfo == null)
        {
          this._portalInfo = new PortalController().GetPortal(this.PortalId);
        }
        return this._portalInfo;
      }
    }




    public Hashtable Settings
    {
      get
      {
        if (this._moduleSettings == null)
        {
          ModuleController controller = new ModuleController();
          this._moduleSettings = new Hashtable(controller.GetModuleSettings(this.ModuleID));

          if (this.TabModuleId != Null.NullInteger)
          {
            Hashtable tabModuleSettings = controller.GetTabModuleSettings(this.TabModuleId);

            foreach (string str in tabModuleSettings.Keys)
              this._moduleSettings[str] = tabModuleSettings[str];
            
          }
        }
        return this._moduleSettings;
      }
      set
      {
        this._moduleSettings = value;
      }
    }




    public int TabId
    { get; set; }





    public int TabModuleId
    { get; set; }





    public UserInfo User
    { get; set; }



  }

}

